/**
 * Licensed by the Bunie Developmentgroup.
 */
package Protocol;

import java.util.HashMap;

/**
 * @author Wouter Class to hold all types used in the protocol
 */
public abstract class PacketTypeKeeper {
    private static HashMap<Integer, String> managementTypeTranslator = null;
    private static HashMap<Integer, String> typeOfPacketsTranslator = null;
    private static HashMap<Integer, String> typeOfUsersTranslator = null;

    public final static int BASICPACKET = 0;
    public final static int TESTPACKET = 1;
    public final static int INLOGREQUESTPACKET = 2;
    public final static int INLOGRESPONSEPACKET = 3;
    public final static int ACCOUNTMANAGEMENTREQUESTPACKET = 6;
    public final static int QUERYREQUESTPACKET = 7;
    public final static int QUERYRESPONSEPACKET = 8;
    public final static int ACCOUNTMANAGEMENTRESPONSEPACKET = 9;
    public final static int NEWQUERYALERTPACKET = 10;
	public final static int COLUMNNAMEPACKET = 11;
    
    public final static int USER = 0;
    public final static int ADMIN = 1;
    
    public final static int INITIAL = 0;
    public final static int ADDACCOUNT = 1;
    public final static int ALTERACCOUNT = 2;
    public final static int DELETEACCOUNT = 3;
    
    private static HashMap<Integer, String> instanceOfManagementTypeTranslator() {
        if (PacketTypeKeeper.managementTypeTranslator == null) {
            PacketTypeKeeper.managementTypeTranslator = new HashMap(4);
            PacketTypeKeeper.managementTypeTranslator.put(PacketTypeKeeper.INITIAL, "intial");
            PacketTypeKeeper.managementTypeTranslator.put(PacketTypeKeeper.ADDACCOUNT, "addAccount");
            PacketTypeKeeper.managementTypeTranslator.put(PacketTypeKeeper.ALTERACCOUNT, "alterAccount");
            PacketTypeKeeper.managementTypeTranslator.put(PacketTypeKeeper.DELETEACCOUNT, "deleteAccount");  
        }
        return PacketTypeKeeper.managementTypeTranslator;
    }
    
    private static HashMap<Integer, String> instanceOftypeOfPacketsTranslator() {
        if (PacketTypeKeeper.typeOfPacketsTranslator == null) {
            PacketTypeKeeper.typeOfPacketsTranslator = new HashMap(11);
            typeOfPacketsTranslator.put(PacketTypeKeeper.INLOGREQUESTPACKET, "inlog request");
            typeOfPacketsTranslator.put(PacketTypeKeeper.INLOGRESPONSEPACKET, "inlog response");
            typeOfPacketsTranslator.put(PacketTypeKeeper.ACCOUNTMANAGEMENTREQUESTPACKET, "account management request");
            typeOfPacketsTranslator.put(PacketTypeKeeper.ACCOUNTMANAGEMENTRESPONSEPACKET, "account management response");
            typeOfPacketsTranslator.put(PacketTypeKeeper.QUERYREQUESTPACKET, "query request");
            typeOfPacketsTranslator.put(PacketTypeKeeper.QUERYRESPONSEPACKET, "query response");
            typeOfPacketsTranslator.put(PacketTypeKeeper.NEWQUERYALERTPACKET, "new query alert");
        }
        return typeOfPacketsTranslator;
    }
    
    private static HashMap<Integer, String> instanceOftypeOfUsersTranslator() {
        if (PacketTypeKeeper.typeOfUsersTranslator == null) {
            PacketTypeKeeper.typeOfUsersTranslator = new HashMap(2);
            typeOfUsersTranslator.put(PacketTypeKeeper.ADMIN, "admin");
            typeOfUsersTranslator.put(PacketTypeKeeper.USER, "user");
        }
        return typeOfUsersTranslator;
    }
    
    /**
     * Methode to translate the int value of a constant to a String representation
     * @param whatToTranslate what constant needs to be translated
     * @return the String representation of the constant
     */
    public static String translate(int whatToTranslate) {
        if (typeOfPacketsTranslator.containsKey(whatToTranslate)) {
            return typeOfPacketsTranslator.get(whatToTranslate);
        }
        if (typeOfUsersTranslator.containsKey(whatToTranslate)) {
            return typeOfUsersTranslator.get(whatToTranslate);
        }
        if (managementTypeTranslator.containsKey(whatToTranslate)) {
            return managementTypeTranslator.get(whatToTranslate);
        }
        return "no translation found";
    }
    
    
}